package com.sc.nft.admin.controller;

import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.IdRequest;
import com.sc.nft.dto.MerchantProductDTO;
import com.sc.nft.dto.MerchantProductUpdateDTO;
import com.sc.nft.feign.MerchantProductClient;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import com.sc.nft.vo.MerchantProductGetByIdVO;
import com.sc.nft.vo.MerchantProductPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品列表(MerchantProduct)表控制层
 *
 * @author wwc
 * @since 2023-03-28 11:05:28
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/merchantProduct")
@Api(tags = "产品列表操作")
public class MerchantProductController {

    private final MerchantProductClient merchantProductClient;

    @PostMapping(value = "/newGoods", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增产品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result newGoods(@RequestBody @Validated MerchantProductDTO merchantProductDTO) {
        return merchantProductClient.newGoods(merchantProductDTO);
    }

    @PostMapping(value = "/getGoodsById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "根据id获取产品信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<MerchantProductGetByIdVO> getGoodsById(@RequestBody @Validated IdRequest idRequest) {
        return merchantProductClient.getGoodsById(idRequest);
    }

    @PostMapping(value = "/updateById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "根据id修改产品信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateById(@RequestBody @Validated MerchantProductUpdateDTO updateDTO) {
        return merchantProductClient.updateById(updateDTO);
    }

    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分页获取产品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<MerchantProductPageVO> page(@RequestBody PageRequest pageRequest) {
        return merchantProductClient.page(pageRequest);
    }

    @PostMapping(value = "/deleteGoodsById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "根据id删除产品信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteGoodsById(@RequestBody @Validated IdRequest idRequest) {
        return merchantProductClient.deleteGoodsById(idRequest);
    }

}
